
<template>
  <div class="wrap">
    <img src="../assets/loginLogo.png" class="logo" alt />
    <div class="form">
      <div class="item">
        <img src="../assets/loginPhone.png" class="phone" alt />
        <input type="text" v-model="tel" placeholder="请输入用户名" />
      </div>
      <div class="item">
        <img src="../assets/pass.png" class="pass" alt />
        <input type="password" v-model="password" placeholder="请输入密码" />
      </div>
      <div class="lou">
        <p class="w_pass" @click="wpass">忘记密码？</p>
      </div>
      <div class="btnBox">
        <button class="login" @click="logins">手机号登陆</button>
        <!-- <button @click="logins">手机号登陆</button> -->
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.wrap {
  overflow: hidden;
  .logo {
    width: 3.426667rem;
    margin: 1.866667rem auto 1.44rem;
  }
  .item {
    width: 6.733333rem;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #3fd9c9;
    height: 1.44rem;
    .phone {
      width: 0.533333rem;
      height: 0.533333rem;
      display: block;
    }
    .pass {
      width: 0.466667rem;
      height: 0.533333rem;
      display: block;
    }
    input {
      display: block;
      outline: none;
      border: none;
      flex: 2;
      margin-left: 15px;
      height: 90%;
      color: #3fd9c9;
    }
  }
  .lou {
    display: flex;
    justify-content: space-between;
    width: 6.733333rem;
    margin: 0 auto;
  }
  .w_pass {
    color: #3fd9c9;
    text-align: left;
    // width: 6.733333rem;
    margin-top: 15px;
  }
  .btnBox {
    margin-top: 1rem;
    button {
      height: 1.133333rem;
      width: 6.813333rem;
      border: 1px solid #3fd9c9;
      border-radius: 30px;
      background: transparent;
      color: #3fd9c9;
      outline: none;
      font-size: 16px;
    }
    .login {
      color: #fff;
      background: #3fd9c9;
      margin-bottom: 0.733333rem;
    }
  }
}
</style>
<script>
import { login } from "@/utils/interface";
import { Dialog } from "vant";

export default {
  data() {
    return {
      tel: "",
      password: "",
      openid: ""
    };
  },
  created() {
    document.title = "登陆";
  },
  methods: {
    logins() {
      if (!this.tel) {
        Dialog.alert({
          message: "请输入账号"
        });
        return false;
      }
      if (!this.password) {
        Dialog.alert({
          message: "请输入密码"
        });
        return false;
      }
      let that = this;
      login({
        account: this.tel,
        password: this.password,
        openId: localStorage.getItem("wechataccess_user_token")
      })
        .then(res => {
          localStorage.setItem("customerwx", res.data.data.jsessionid);
          if (
            that.getUrlParams("state") &&
            that.getUrlParams("state") != "STATE"
          ) {
            window.location.href =
              "http://www.jiebaodingdan.com/customer-mobile?state=" +
              that.getUrlParams("state") +
              "/#/follow";
          } else {
            that.$router.replace("/");
          }
          
          
        })
        .catch(e => {
          console.log(e);
        });
    },
    wpass() {
      if (this.getUrlParams("state") && this.getUrlParams("state") != "STATE") {
        window.location.href =
          "http://www.jiebaodingdan.com/customer-mobile?state=" +
          this.getUrlParams("state") +
          "/#/wpass";
      } else {
        this.$router.push("/wpass");
      }
    },

    getUrlParams(name) {
      // 不传name返回所有值，否则返回对应值
      var url = window.location.search;
      if (url.indexOf("?") == 1) {
        return false;
      }
      url = url.substr(1);
      url = url.split("&");
      var name = name || "";
      var nameres;
      // 获取全部参数及其值
      for (var i = 0; i < url.length; i++) {
        var info = url[i].split("=");
        var obj = {};
        obj[info[0]] = decodeURI(info[1]);
        url[i] = obj;
      }
      // 如果传入一个参数名称，就匹配其值
      if (name) {
        for (var i = 0; i < url.length; i++) {
          for (const key in url[i]) {
            if (key == name) {
              nameres = url[i][key];
            }
          }
        }
      } else {
        nameres = url;
      }
      // 返回结果
      return nameres;
    }
  }
};
</script>
<style lang="scss" scoped>
</style>

